<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ page import="java.util.*" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="lwhy.StudentBean"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=uft-8">
<title>学生列表</title>
<style type="text/css">td,th{ padding:5px;}</style>
</head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/jsp";
String username = "root";
String password = "root";
Connection conn = DriverManager.getConnection(url,username,password);
Statement stmt = conn.createStatement();
String sql= "select*from tb_student";
ResultSet rs= stmt.executeQuery(sql);
List<StudentBean> list = new ArrayList<>();
while(rs.next()){
	StudentBean student = new StudentBean();
	student.setName(rs.getString("name"));

	
    list.add(student);
}


%>

<table width="98%" border="0" align="center" cellpadding="0"
cellspacing="1" bgcolor="#666666">
<tr>
<th bgcolor="#FFFFFF">姓名</th>


</tr>
<%

if (list == null ||list.size()<1){
  out.print("<tr><td bgcolor='#FFFFFF' colspan='5'>没有学生信息</td></tr>");
} else {
for(StudentBean student : list){
%>
<tr align="center">
<td bgcolor="#FFFFFF" ><%=student.getName()%></td> 


</tr>
<%}
}
%>
</table>  

</body>
</html>